import { createRouter, createWebHistory } from 'vue-router'
const token = localStorage.getItem('token')
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    // 引导页
    {
      path: '/',
      name: 'guide',
      component: () => import('../views/guide/guideView.vue'),
    },
    // 商城客服
    {
      path: '/customer',
      name: '客服',
      component: () => import('../views/customer/customerIndex.vue')
    },
    // 地址页
    {
      path: '/myaddress',
      name: 'myaddress',
      component: () => import('../views/myaddress/myaddressIndex.vue'),
    },
    // 极速问诊
    {
      path: '/socket',
      name: 'socket',
      component: () => import('../views/socket/socketIndex.vue'),
    },
      {
      path: '/socket2',
      name: 'socket2',
      component: () => import('../views/socket2/index.vue'),
    },
    // 首页搜索页
    {
      path: '/search',
      name: 'search',
      component: () => import('../views/search/searchVIew.vue'),
    },
    // 预约挂号
    {
      path: '/reservation',
      name: 'reservation',
      component: () => import('../views/reservation/reservationIndex.vue'),
    },
    // 预约挂号详情
    {
      path: '/reservationDetail',
      name: 'reservationDetail',
      component: () => import('../views/reservationDetail/reservationDetailIndex.vue')
    },
    // 预约挂号详情-医生
    {
      path: '/expertRegister',
      name: 'expertRegister',
      component: () => import('../views/home-expertRegister/expertRegisterIndex.vue')
    },
    // 开药门诊
    {
      path: '/prescribe',
      name: 'prescribe',
      component: () => import('../views/prescribe/prescribeIndex.vue')
    },
    // 复诊开方
    {
      path: '/squareRoot',
      name: 'squareRoot',
      component: () => import('../views/squareRoot/squareRootIndex.vue')
    },
    // 问专家详情页
    {
      path: '/homeDetail',
      name: 'homeDetail',
      component: () => import('../views/homeDetail/homeDetail.vue'),
    },
    // 在线咨询详情
    {
      path: '/consultNext',
      name: 'consultNext',
      component: () => import('../views/consultNext/consultNextIndex.vue')
    },
    // 新建档案
    {
      path: '/xjda',
      name: 'xjda',
      component: () => import('../views/home-files/xjdaIndex.vue')
    },
    // 首页支付
    {
      path: '/pay',
      name: 'pay',
      component: () => import('../views/home-payment/payIndex.vue')
    },
    // 评论更多
    {
      path: '/commentMore',
      name: 'commentMore',
      component: () => import('../views/commentMore/commentMoreIndex.vue')
    },
    // 健康科普
    {
      path: '/health',
      name: 'health',
      component: () => import('../views/health/healthIndex.vue')
    },
    // 健康科普详情页
    {
      path: '/healthDetail',
      name: 'healthDetail',
      component: () => import('../views/healthDetail/healthDetailIndex.vue')
    },
    // 咨询详情页
    {
      path: '/consultDetail',
      name: 'consultDetail',
      component: () => import('../views/consultDetail/consultDetailIndex.vue')
    },
    // 答谢医生
    {
      path: '/thankYou',
      name: 'thankYou',
      component: () => import('../views/thankYou/thankYouIndex.vue')
    },
    // 为您推荐详情
    {
      path: '/recommendDetail',
      name: 'recommendDetail',
      component: () => import('../views/recommendDetail/recommendDetailIndex.vue')
    },
    // 首页更多
    {
      path: '/homeMore',
      name: 'homeMore',
      component: () => import('../views/homeMore/homeMore.vue'),
    },
    {
      path: '/layout',
      name: 'home',
      redirect: '/home',
      component: () => import('../views/layout/layoutIndex.vue'),
      children: [
        {
          path: '/home',
          meta: {
            title: '首页',
          },
          component: () => import('../views/home/homeIndex.vue'),
        },
        {
          path: '/message',
          meta: {
            title: '消息',
          },
          component: () => import('../views/message/msgIndex.vue'),
        },
        {
          path: '/shop',
          meta: {
            title: '商城',
          },
          component: () => import('../views/shop/index.vue'),
        },
        {
          path: '/case',
          meta: {
            title: '患者案例',
          },
          component: () => import('../views/case/index.vue'),
        },
        {
          path: '/mine',
          meta: {
            title: '我的',
          },
          component: () => import('../views/mine/mineIndex.vue'),
        },
        {
          path: '/detail',
          meta: {
            title: '详情',
          },
          component: () => import('../views/detail/index.vue'),
        },
        {
          path: '/medic',
          meta: {
            title: '详情',
          },
          component: () => import('../views/medic/index.vue'),
        },
        {
          path: '/login',
          meta: {
            title: '登录',
          },
          component: () => import('../views/login/loginIndex.vue'),
        },
        {
          path: '/synthesis',
          meta: {
            title: '综合',
          },
          component: () => import('../views/synthesis/index.vue'),
        },
      ],
    },
    {
      path: '/more',
      name: '更多',
      component: () => import('../views/more/index.vue'),
    },
    {
      path: '/order',
      name: '支付',
      component: () => import('../views/order/index.vue'),
    },
    {
      path: '/service',
      name: '我的医生',
      component: () => import('../views/service/index.vue'),
    },
    {
      path: '/broadcast',
      name: '视频',
      component: () => import('../views/broadcast/index.vue'),
    },
    {
      path: '/interrogation',
      name: '专家问诊',
      component: () => import('../views/interrogation/index.vue'),
    },
    {
      path: '/register',
      name: '挂号记录',
      component: () => import('../views/register/index.vue'),
    },
    {
      path: '/fl',
      name: '分类',
      component: () => import('../views/fl/index.vue'),
    },
    {
      path: '/cart',
      name: '购物车',
      component: () => import('../views/cart/index.vue'),
    },
    {
      path: '/restoratives',
      name: '我的用药',
      component: () => import('../views/restoratives/index.vue'),
    },
    {
      path: '/mywz',
      name: '我的问诊',
      component: () => import('../views/mywz/index.vue'),
    },
    {
      path: '/patient-detail',
      name: '患者详情',
      component: () => import('../views/patient-detail/index.vue'),
    },
    {
      path: '/treatment',
      name: '案例活动',
      component: () => import('../views/treatment/index.vue'),
    },
    {
      path: '/releasek',
      name: '发布',
      component: () => import('../views/releasek/index.vue'),
    },
    {
      path: '/shopdetail/:id',
      name: '商场详情',
      component: () => import('../views/shopdetail/index.vue'),
    },
    {
      path: '/detail',
      meta: {
        title: '详情',
      },
      component: () => import('../views/detail/index.vue'),
    },
    // 设置
    {
      path: '/emit',
      name: 'emit',
      component: () => import('../views/emit/emitInde.vue'),
    },
    // 登录
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/login/loginIndex.vue'),
    },
    // 修改昵称
    {
      path: '/emit-emit',
      name: 'emit-emit',
      component: () => import('../views/emit-emit/emittIndex.vue'),
    },
    // 在线问诊
    {
      path: '/zxwz',
      name: 'zxwz',
      component: () => import('../views/box/zxwz/zxwzIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 健康档案
    {
      path: '/jkda',
      name: 'jkda',
      component: () => import('../views/box/jkda/jkdaIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 用药建议
    {
      path: '/yyjy',
      name: 'yyjy',
      component: () => import('../views/box/yyjy/yyjyIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 优选订单
    {
      path: '/yxdd',
      name: 'yxdd',
      component: () => import('../views/box/yxdd/yxddIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 我的医生
    {
      path: '/wdys',
      name: 'wdys',
      component: () => import('../views/box/wdys/wdysIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 随访计划
    {
      path: '/sfjh',
      name: 'sfjh',
      component: () => import('../views/box/sfjh/sfjhIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 我的订单
    {
      path: '/myshop',
      name: 'myshop',
      component: () => import('../views/boxs/myshop/myshopIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 挂号订单
    {
      path: '/orden',
      name: 'orden',
      component: () => import('../views/boxs/orden/orderIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 收货地址
    {
      path: '/address',
      name: 'address',
      component: () => import('../views/boxs/address/addressIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 我的卡券
    {
      path: '/mycard',
      name: 'mycard',
      component: () => import('../views/boxs/mycard/mycardIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 门诊预约
    {
      path: '/make',
      name: 'make',
      component: () => import('../views/boxs/make/makeIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 商品收藏
    {
      path: '/collection',
      name: 'collection',
      component: () => import('../views/boxs/collection/collectionIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 意见反馈
    {
      path: '/feedback',
      name: 'feedback',
      component: () => import('../views/boxs/feedback/feedbackIndex.vue'),
    },
    // 引导页
    {
      path: '/setp',
      name: 'setp',
      component: () => import('../views/step/stepIndex.vue'),
    },
    // 权益中心
    {
      path: '/member',
      name: 'member',
      component: () => import('../views/member/memberIndex.vue'),
      beforeEnter: (to, from, next) => {
        if (token) {
          next()
        } else {
          next('/login')
        }
      },
    },
    // 注册
    {
      path: '/logon',
      name: 'logon',
      component: () => import('../views/logon/logonIndex.vue'),
    },
    {
      path: '/detail',
      meta: {
        title: '详情',
      },
      component: () => import('../views/detail/index.vue'),
    },
    {
      path: '/dizi',
      meta: {
        title: '地址',
      },
      component: () => import('../views/dizi/index.vue'),
    },
    // 协议
    {
      path: '/agreement',
      name: 'agreement',
      component: () => import('../views/agreement/agreementIndex.vue'),
    },
    {
      path: '/shopss',
      name: '搜索',
      component: () => import('../views/shopss/index.vue'),
    },
    {
      path: '/xjda',
      name: '新建档案',
      component: () => import('../views/box/xjda/xjdaIndex.vue'),
    },
    // {
    //   path: '/order',
    //   name: '新建档案',
    //   component: () => import('../views/boxs/order/orderIndex.vue'),
    // },
    {
      path: '/disease',
      name: '疾病百科',
      component: () => import('../views/disease/index.vue'),
    },
    {
      path: '/address-add',
      name: '/address-add',
      component: () => import('../views/boxs/address/address-add/address-addIndex.vue'),
    },
    //详情路由
    {
      path: '/reservationDetail',
      name: 'reservationDetail',
      component: () => import('../views/reservationDetail/reservationDetailIndex.vue'),
    },
    {
      path: '/expertRegister',
      name: 'expertRegister',
      component: () => import('../views/home-expertRegister/expertRegisterIndex.vue'),
    },
    {
      path: '/customer',
      name: '客服',
      component: () => import('../views/customer/customerIndex.vue')
    },
      // 关于我们
    {
      path:'/about',
      name:'about',
      component:()=>import('../views/boxs/about/aboutIndex.vue')
    },
      // 隐私政策及简明版
    {
      path:'/jian',
      name:'jian',
      component:()=>import('../views/boxs/jian/jianIndex.vue')
    },
     // 价格公示
    {
      path:'/sprice',
      name:'sprice',
      component:()=>import('../views/boxs/sprice/spriceIndex.vue')
    },
  ],
})
router.beforeEach((to,from,next)=>{
  if(!localStorage.getItem('token')){
    if(to.path=='/login'){
      next()
    }else{
      next('/login')
    }
  }else{
    if(to.path =='/login'){
      next('/')
    }
  }
  next()
})
export default router
